<script setup lang='ts'>
  import { reactive, shallowRef, ref, nextTick } from 'vue';
  import { guild_roomApi } from '@/api/controller';
  import violationList from './violationList.vue';
  import wealthlist from './wealthlist.vue';
  import shotoffList from './shotoffList.vue';
  import durationlist from './durationlist.vue';
  import partitioning from './partitioning.vue';
  import { ElMessageBox } from 'element-plus';
  const $emit = defineEmits(['updateList'])
  import { ToastSuccess, Toastloading } from '@/utils/public';
  const unionFormDom = shallowRef(),
  componentRef = ref();
  const action = reactive({
    drawerDialog:false,
    title:'',
    is_hide:0 as number,
  })
  let unionObj = {} as any
  const handleDialog = (name:any = '')=>{
    unionFormDom.value = name
    nextTick(()=>{
      componentRef.value.openDialog(unionObj)
    })
  }
  const openDialog = (row:any = {})=>{
    action.drawerDialog = true
    const { name='', is_hide=0 } = row
    action.is_hide = is_hide
    action.title = `房间：${name}`
    unionObj = row
  }
  const handleRoomShow = (is_hide:number = 0)=>{
    ElMessageBox.confirm(`确定${is_hide==1?'隐藏':'显示'}${action.title}吗?`, "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(async () => {
      const loading = Toastloading();
      guild_roomApi.hideRoom({
        room_id:unionObj.room_id,
        is_hide
      }).then(()=>{
        ToastSuccess("操作成功!");
        loading.close();
        $emit('updateList')
        action.drawerDialog = false
      }).catch(()=>{
        loading.close();
      })
    }).catch(() => {});
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-drawer
      v-model="action.drawerDialog"
      :title="action.title"
      direction="rtl"
      class="drawerDialog"
    >
    <el-row>
        <el-col :span="8">
          <el-button type="primary" @click="handleDialog(wealthlist)">房间流水</el-button>
        </el-col>
        <!-- <el-col :span="8">
          <el-button type="primary" @click="handleDialog(violationListRef)">违规记录</el-button>
        </el-col> -->
        <el-col :span="8">
          <el-button type="primary" @click="handleDialog(durationlist)">开厅时长</el-button>
        </el-col>
        <el-col :span="8">
          <el-button type="primary" @click="handleDialog(shotoffList)">踢人列表</el-button>
        </el-col>
        <el-col :span="8">
          <el-button v-rule="'getRoomFinanceUser'" type="primary" @click="handleDialog(partitioning)">指定分成ID</el-button>
        </el-col>
        <el-col :span="8">
          <el-button v-if="action.is_hide == 0" type="danger" @click="handleRoomShow(1)">隐藏房间</el-button>
          <el-button v-if="action.is_hide == 1" type="success" @click="handleRoomShow(0)">显示房间</el-button>
        </el-col>
      </el-row>
    </el-drawer>
    <component ref="componentRef" :is="unionFormDom" ></component>
    <!-- <violationList ref="violationListRef" />
    <durationlist ref="durationlistRef" />
    <shotoffList ref="shotoffListRef" />
    <wealthlist ref="wealthlistRef" />
    <partitioning ref="partitioningRef" /> -->
  </div>
</template>

<style lang='scss' scoped>
  :deep(.drawerDialog) {
    .el-col {
      margin-bottom: 10px;
    }
  }
</style>
